package com.lge.clock.alarmclock;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.lge.clock.R;

/**
 * @author LGE Cappuccino
 */
public class StopSnoozeButton extends LinearLayout implements OnClickListener
{
	private StopSnoozeButton myself; 
	private Button mStopButton;
	private Button mSnoozeButton;
	
	private StopListener mStopListener;	
	/**
	 * @author sungtan.back
	 */
	public interface StopListener{
		/**
		 * Method stopChanged.
		 */
		void stopChanged();
	}	 
	
	private SnoozeListener mSnoozeListener;	
	/**
	 * @author sungtan.back
	 */
	public interface SnoozeListener{
		/**
		 * Method snoozeChanged.
		 */
		void snoozeChanged();
	}
	
	/**
	 * Constructor for StopSnoozeButton.
	 * @param context Context
	 */
	public StopSnoozeButton(Context context) {
		this(context, null);
	}  
	/**
	 * Constructor for StopSnoozeButton.
	 * @param context Context
	 * @param attrs AttributeSet
	 */
	public StopSnoozeButton(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}           
	
	/**
	 * Constructor for StopSnoozeButton.
	 * @param context Context
	 * @param attrs AttributeSet
	 * @param defStyle int
	 */
	public StopSnoozeButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		LayoutInflater inflater = (LayoutInflater) context.getSystemService("layout_inflater");
		myself = (StopSnoozeButton)inflater.inflate(R.layout.alarm_stopsnoozebutton, this, true);
		
		mStopButton = (Button) myself.findViewById(R.id.stopbutton);
		mSnoozeButton = (Button) myself.findViewById(R.id.snoozebutton);
		
		mStopButton.setOnClickListener(this);
		mSnoozeButton.setOnClickListener(this);
	}
	
	/**
	 * Method onClick.
	 * @param v View
	 * @see android.view.View$OnClickListener#onClick(View)
	 */
	public void onClick(View v) {
		if( v.equals(mStopButton) ) {
			stopChanged();
		}
		else if( v.equals(mSnoozeButton) ) {
			//mStopButton.setClickable(false);
			snoozeChanged();
		}
	}
	
	public void setStopListener(StopListener aa) {
        mStopListener = aa ;
    }    
    public void setSnoozeListener(SnoozeListener aa) {
        mSnoozeListener = aa ;
    }
    
    private void stopChanged() {
    	if ( mStopListener != null )
    		mStopListener.stopChanged();
    }
    
    private void snoozeChanged() {
    	if ( mSnoozeListener != null )
    		mSnoozeListener.snoozeChanged();
	}
    
    public void setPuzzleOn(boolean flag) {
    	if( flag ) {
    		if ( mStopButton != null )
    			mStopButton.setVisibility(View.GONE);
    	}
    	else {
    		if ( mStopButton != null )
    			mStopButton.setVisibility(View.VISIBLE);
    	}
    }
}